<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3" xmlns:head="http://www.w3.org/1999/html">
<head th:include="public/public_css::public_css ('库位组管理')"/>

<body style="background-color: #f2f2f2;">
<div class="layui-fluid larry-wrapper">
    <div class="layui-card">
        <div class="layui-row layui-col-space30">
            <div class="layui-col-xs24">
                <form class="layui-form layui-card-header  layui-card-header-auto" id="searchForm">
                    <div class="layui-inline">
                        <label class="layui-form-label">货主名称</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="mc" name="mc" placeholder="货主名称"/>
                        </div>
                    </div>

                    <div class="layui-inline inline-search-btn">
                        <a class="layui-btn layui-btn-normal" data-type="reload" id="search_button"> 搜索 </a>
                    </div>
                    <div class="layui-inline inline-reset-btn">
                        <button type="reset" class="layui-btn layui-btn-primary" style="background-color: #40AFFE">重置</button>
                    </div>
                </form>
                <div class="group-button" id="toolbar">

                    <a class="layui-btn layui-btn-sm layui-btn-normal add-btn">
                        <i class="layui-icon">&#x1005;</i> 新增
                    </a>
                    <a class="layui-btn layui-btn-sm layui-btn-normal edit-btn">
                        <i class="layui-icon">&#x1005;</i> 修改
                    </a>
                    <!-- Single button -->
                 <!--   <div class="btn-group">
                        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"
                                aria-haspopup="true" aria-expanded="false">
                            多选操作 <span class="caret"></span>
                        </button>
                        <ul class="dropdown-menu">
                            <li><a id="btn_jin" href="#">禁用</a></li>
                            <li><a id="btn_qi" href="#">启用</a></li>
                        </ul>
                    </div>-->
                </div>
                <!--列表-->
                <section class="panel panel-padding layui-card-body">
                    <div class="pro">
                        <table id="table"></table>
                    </div>
                </section>
            </div>
        </div>
    </div>
</div>

</body>


<div th:include="/public/public_js::public_js"></div>
<style type="text/css">
    .moreBtn {
        width: 50px;
        height: 20px;
        text-align: center;
        color: #fff;
        line-height: 20px;
        background-color: #eee;
        position: relative;
        margin: 0 auto;
        cursor: pointer;
    }

    .moreBtn:before {
        content: '';
        display: block;
        width: 35px;
        height: 20px;
        position: absolute;
        transform: skewX(30deg);
        background: #eee;
        border-top-left-radius: 8px;
        left: -20px;
        top: 0;
    }

    .moreBtn:after {
        content: '';
        display: block;
        width: 35px;
        height: 20px;
        position: absolute;
        transform: skewX(-30deg);
        background: #eee;
        border-top-right-radius: 8px;
        top: 0;
        right: -20px;
    }
</style>
<script>
    //	回车查询
    document.onkeydown = function(event) {
        e = event ? event : (window.event ? window.event : null);
        if (e.keyCode == 13) {
            //执行的方法
            $('#search_button').click();
        }
    };
    layui.use(['list', 'layer', 'zzpUtils', 'jquery', 'laydate'], function () {
        window.operateEvent = {
            "click .layui-btn-primary": function (e, value, row, index) {
                /*这里激活状态那个按钮用不到，啥都不需要写，只读*/
            },
            "click #editRow": function (e, value, row, index) {//行按钮编辑  btn_stop
                editDialog(row.id, row.sfyx);
            },
            "click #btn_stop": function (e, value, row, index) {//行按钮禁用
                stopDialog(row.id);
            },
            "click #btn_start": function (e, value, row, index) {//行按钮启用
                startDialog(row.id);
            },
            "click #searchRow": function (e, value, row, index) {//行按钮查看
                cha_kuwei(row.id);
            }
        }

        var zzpUtils = layui.zzpUtils,
            $ = layui.jquery,
            laydate = layui.laydate;
        //编辑库位组
        function editDialog(id, sfyx) {
            if (sfyx == 0) {
                layer.msg("该库区已禁用，不可编辑！");
            } else {
                zzpUtils.dialog({
                    title: "修改库位组",
                    type: 2,
                    content: "/wmslibrarypositiongroup/edit?id=" + id,
                    area: ['55%', '55%'], //设置dialog大小，也可以不设置，
                    end: function () {//修改成功后刷新
                        zzpUtils.refreshTable("#table");
                    }
                });
            }
        }

        //禁用库位组
        function stopDialog(id) {
            var ids = [];
            ids.push(id);
            zzpUtils.confirm("是否确定禁用库位组", function (index) {
                zzpUtils.action({
                    url: "/wmslibrarypositiongroup/bjh" ,
                    data: JSON.stringify({ids:ids}),
                    success: function (data) {
                        setTimeout(function () {
                            layer.msg(data.title);
                        }, 500);
                        zzpUtils.refreshTable("#table");
                    }, error: function (xhr, textStatus) {
                        console.log(textStatus);
                        console.log(xhr)
                    }
                })
            })
            return false;

        }

        //启用库位组
        function startDialog(id) {
            var ids = [];
            ids.push(id);
            zzpUtils.confirm("是否确定启用库区", function (index) {
                zzpUtils.action({
                    url: "/wmslibrarypositiongroup/yjh" ,
                    data: JSON.stringify({ids:ids}),
                    success: function (data) {
                        setTimeout(function () {
                            layer.msg(data.title);
                        }, 500);
                        zzpUtils.refreshTable("#table");
                    }, error: function (xhr, textStatus) {
                        console.log(textStatus);
                        console.log(xhr)
                    }
                })
            })
            return false;
        }
        var $table = zzpUtils.table({
            elem: '#table',
            isApi: true,
            pagination: true,
            url: '/wmsOwner/list',
            columns: [{
                field: '',
                checkbox: true
            }, {
                field: 'mc',
                title: '货主名称'
            }, {
                field: 'lxr',
                title: '联系人'
            },  {
                field: 'dz',
                title: '地址'
            },{
                field: 'caozuo',
                title: '操作',
                events: operateEvent,
                formatter: operateFormatter
            }],
            queryParams: function () {//查询条件
                return zzpUtils.getFormJson($("#searchForm"));
            },
            detailFormatter: function (index, row) {
                return "这里就没有确定过11";
            },
            onDblClickRow:function ( row,index) {/*双击行展示详情*/
                btn_cha(row.id);
            }
        });
        $(".inline-search-btn").on('click',function () {
            zzpUtils.refreshTable("#table");
        })
        /*表格右侧按钮*/
        function operateFormatter(value, row, index) {
            if (row.sfyx == 1) {//启用
                return [
                    '<a class="layui-btn layui-btn-primary layui-btn-xs" id="searchRow" >查看</a>',
                    '<a class="layui-btn layui-btn-xs" id="editRow">修改</a>',
                    '<a class="layui-btn layui-btn-danger layui-btn-xs" id="btn_stop">禁用</a>'
                ].join('')
            } else {//禁用
                return [
                    /* '<a class="layui-btn layui-btn-primary layui-btn-xs" >查看</a>',*/
                    /*'<a class="layui-btn layui-btn-xs" id="editRow">修改</a>',*/
                    '<a class="layui-btn layui-btn-danger layui-btn-xs" id="btn_start">启用</a>'
                ].join('')
            }

        }
        //查询
        $(".inline-search-btn").on('click', function () {
            zzpUtils.refreshTable("#table");
        })
        /*跳新增货主*/
        $(".add-btn").on('click', function () {
            zzpUtils.dialog({
                title: "新增货主",
                type: 2,
                content: "/ownerRouter/toAddowner",
                area: ['55%', '70%'], //设置dialog大小，也可以不设置，
                end: function () {//增加成功后刷新
                    zzpUtils.refreshTable("#table");
                }
            });
        })
        //编辑库位组
        function editDialog(id, sfyx) {
            if (sfyx==0) {
                layer.msg("该库位组已禁用，不可编辑！");
            } else {
                zzpUtils.dialog({
                    title: "修改库位组",
                    type: 2,
                    content: "/groupRouter/toEditgroup?id=" + id,
                    area: ['55%', '55%'], //设置dialog大小，也可以不设置，
                    end: function () {//修改成功后刷新
                        zzpUtils.refreshTable("#table");
                    }
                });
            }
        }
        /*顶部按钮编辑库位组*/
        $(".edit-btn").on('click', function () {
            var $rows = $table.bootstrapTable('getSelections');
            if ($rows.length == 1) {
                var ids = $.map($rows, function (row) {
                    return row.id;
                })
                if($rows[0].sfyx==0){
                    layer.msg("该库位组已禁用，不可编辑！");
                }else {
                    zzpUtils.dialog({
                        title: "修改位组",
                        type: 2,
                        content: "/groupRouter/toEditgroup?id=" + ids,
                        area: ['55%', '55%'], //设置dialog大小，也可以不设置，
                        end: function () {//修改成功后刷新
                            zzpUtils.refreshTable("#table");
                        }
                    });
                }
            } else {
                layer.msg("请选择一条进行修改");
            }
        })
        /*顶部按钮多选禁用*/
        $("#btn_jin").on('click', function () {
            var index = 0;
            var $rows = $table.bootstrapTable('getSelections');
            //判断选中的库区里是否有已经禁用的
            for (var i = 0; i < $rows.length; i++) {
                if ($rows[i].sfyx == 0) {
                    index++;
                }
            }
            if (index > 0) {
                layer.msg("您选择的库位组有已经禁用的，请重选！");
            } else if ($rows.length == 0) {
                layer.msg("请选择一条进行禁用");
            } else {
                var ids = $.map($rows, function (row) {
                    return row.id;
                })
                zzpUtils.confirm("是否确定禁用库位组", function (index) {
                    zzpUtils.action({
                        url: "/wmslibrarypositiongroup/bjh",
                        data: JSON.stringify({ids:ids}),
                        success: function (data) {
                            setTimeout(function () {
                                layer.msg(data.title);
                            }, 500);
                            zzpUtils.refreshTable("#table");
                        }, error: function (xhr, textStatus) {
                            console.log(textStatus);
                            console.log(xhr)
                        }
                    })
                })
                return false;
            }
        })
        /*顶部按钮多选启用*/
        $("#btn_qi").on('click', function () {
            var index = 0;
            var $rows = $table.bootstrapTable('getSelections');
            //判断选中的库区里是否有已经启用的
            for (var i = 0; i < $rows.length; i++) {
                if ($rows[i].sfyx == 1) {
                    index++;
                }
            }
            if (index > 0) {
                layer.msg("您选择的库位组有已启用的，请重选！");
            } else if ($rows.length == 0) {
                layer.msg("请选择一条信息进行启用");
            } else {
                var ids = $.map($rows, function (row) {
                    return row.id;
                })
                zzpUtils.confirm("是否确定启用库位组", function (index) {
                    zzpUtils.action({
                        url: "/wmslibrarypositiongroup/yjh",
                        data: JSON.stringify({ids:ids}),
                        success: function (data) {
                            setTimeout(function () {
                                layer.msg(data.title);
                            }, 500);
                            zzpUtils.refreshTable("#table");
                        }, error: function (xhr, textStatus) {
                            console.log(textStatus);
                            console.log(xhr)
                        }
                    })
                })
                return false;
            }
        })
    });

    /*查看库位*/
    function cha_kuwei(id) {
        var zzpUtils = layui.zzpUtils,
            $ = layui.jquery,
            laydate = layui.laydate;
        zzpUtils.dialog({
            title: "查看库位",
            type: 2,
            content: "/groupRouter/toChakanKw?id=" + id,
            area: ['70%', '70%'], //设置dialog大小，也可以不设置，
        });
    }

    /*双击查看详情*/
    function btn_cha(id){
        var zzpUtils = layui.zzpUtils,
            $ = layui.jquery,
            laydate = layui.laydate;
        zzpUtils.dialog({
            title: "货主详情",
            type: 2,
            content: "/ownerRouter/getFindHz?id=" + id,
            area: ['80%', '80%'], //设置dialog大小，也可以不设置，
        });

    }
</script>
</html>